headerbar: compute nominal size of sides up front
authorRay Strode <rstrode@redhat.com>
Fri, 24 Jun 2016 16:16:40 +0000 (12:16 -0400)
committerRay Strode <rstrode@redhat.com>
Sat, 25 Jun 2016 00:24:43 +0000 (20:24 -0400)
In order to support the expand property on children, we're
going to need to look at the size of the packed children
on each side of the title widget, up front, before allocating
them (to compute how much extra allocation each expanded child
gets).

This commit lays the groundwork for that analysis by splitting
the size calculation of each side of the header bar outside
of the loop that allocates each child of the header bar.

https://bugzilla.gnome.org/show_bug.cgi?id=724332

gtk/gtkheaderbar.c

index eba695b8abd32d1dcdb900330932c5ae8ce090fe..031199b2a7aa62b9c1d0ec14be4b95f50aad28ad 100644 (file)
@@ -1074,7 +1074,28 @@ gtk_header_bar_allocate_contents (GtkCssGadget        *gadget,
 
   width = gtk_distribute_natural_allocation (MAX (0, width), nvis_children, sizes);
 
-  side[0] = side[1] = 0;
+  /* compute the nominal size of the children filling up each side of
+   * the title in titlebar
+   */
+  side[0] = start_width;
+  side[1] = end_width;
+  for (packing = GTK_PACK_START; packing <= GTK_PACK_END; packing++)
+    {
+      i = 0;
+      for (l = priv->children; l != NULL; l = l->next)
+        {
+          child = l->data;
+          if (!gtk_widget_get_visible (child->widget))
+            continue;
+
+          if (child->pack_type == packing)
+            side[packing] += sizes[i].minimum_size + priv->spacing;
+
+          i++;
+        }
+    }
+
+  /* allocate the children on both sides of the title */
   for (packing = GTK_PACK_START; packing <= GTK_PACK_END; packing++)
     {
       child_allocation.y = allocation->y;
@@ -1111,8 +1132,6 @@ gtk_header_bar_allocate_contents (GtkCssGadget        *gadget,
               x -= priv->spacing;
             }
 
-          side[packing] += child_size + priv->spacing;
-
           if (direction == GTK_TEXT_DIR_RTL)
             child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
 
@@ -1123,9 +1142,6 @@ gtk_header_bar_allocate_contents (GtkCssGadget        *gadget,
         }
     }
 
-  side[0] += start_width;
-  side[1] += end_width;
-
   /* We don't enforce css borders on the center widget, to make
    * title/subtitle combinations fit without growing the header
    */